package com.fastloan.mgt.invest.model.count;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by gelon on 2017/10/16.
 */
public class AnswerCount {

    String details;
    int num;
    List<AnswerDetail> answerDetails;
    String percentage;

    public String getDetails() {
        return details;
    }

    public AnswerCount setDetails(String details) {
        this.details = details;
        return this;
    }

    public int getNum() {
        return num;
    }

    public AnswerCount setNum(int num) {
        this.num = num;
        return this;
    }

    public List<AnswerDetail> getAnswerDetails() {
        return answerDetails;
    }

    public AnswerCount setAnswerDetails(List<AnswerDetail> answerDetails) {
        this.answerDetails = answerDetails;
        return this;
    }

    public void plusNum() {
        this.num++;
    }

    public String getPercentage() {
        return percentage;
    }

    public AnswerCount setPercentage(String percentage) {
        this.percentage = percentage;
        return this;
    }


    public void generPercentage(int total) {
        if (total == 0) {
            percentage = "0%";
        } else {
            percentage =
                new BigDecimal(num).divide(new BigDecimal(total), 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(2).toString()
                    + "%";
        }
    }
}
